package com.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * 78. 子集
 * 迭代法实现子集枚举
 *
 * @author fy
 * @date 2022/4/29 11:50
 */
public class Solution78_2 {

    List<Integer> t = new ArrayList<Integer>();
    List<List<Integer>> ans = new ArrayList<List<Integer>>();

    public List<List<Integer>> subsets(int[] nums) {
        int n = nums.length;
        for (int mask = 0; mask < (1 << n); ++mask) {
            t.clear();
            for (int i = 0; i < n; ++i) {
                if ((mask & (1 << i)) != 0) {
                    t.add(nums[i]);
                }
            }
            ans.add(new ArrayList<Integer>(t));
        }
        return ans;
    }

}
